package playn.platformer;

import java.util.ArrayList;
import java.util.Iterator;

import tiled.simple.core.MapObject;
import tiled.simple.core.TMXObjectsProvider;

import playn.platformer.entities.Mask;
import playn.platformer.entities.Sonic;

public class MapObjectsProvider implements TMXObjectsProvider{
	private Game game;

	public MapObjectsProvider(Game game) {
		this.game=game;
	}

	private ArrayList<Entity> entities = new ArrayList<Entity>();
	
	public void object(MapObject mapObject) {
		
		if(mapObject.getType().equalsIgnoreCase("Hero")){
			Sonic sonic=new Sonic(game,mapObject);
			entities.add(sonic);
		}
		
		if(mapObject.getType().equalsIgnoreCase("Mask")){
			Mask mask=new Mask(game,mapObject);
			entities.add(mask);
		}

	}
	
	public void render(){
		Iterator<Entity> itr=entities.iterator();
		while (itr.hasNext()) {
			Entity entity=itr.next();
			entity.render();
		}
	}

	public void update(float delta){
		Iterator<Entity> itr=entities.iterator();
		while (itr.hasNext()) {
			Entity entity=itr.next();
			entity.update(delta);
		}
	}

}
